//
// Created by nilyang on 2022/1/8.
//

#include "concepts.h"
#include <iostream>

template<IsInteger T>
T func_concepts_add(T a, T b) {
    return a + b;
}

template<IsNumber T>
T func_concepts_add(T a, T b) {
    return a + b;
}

template<IsNumber T, IsNumber U>
float func_concepts_add(T a, U b) {
    return (float )(a + b);
}

int func_concepts_test() {
    using namespace std;
    cout << "func_concepts_add(1, 2) = " << func_concepts_add(1,2) << endl;
    // C++ 20: 如果不定义 IsNumber 以下语句无法通过编译，编译阶段直接检查出不符合概念要求!
    // C++ 20: 定义了 IsNumber 概念才能通过编译！
    cout << "func_concepts_add(1.0, 2.0) = " << func_concepts_add(1.0, 2.0) << endl;
    //no matching function for call to 'func_concepts_add'
    //candidate template ignored: constraints not satisfied [with T = double]
    //because 'double' does not satisfy 'IsInteger'
    //because 'typename is_integer<T>::type' would be invalid:
    //  implicit instantiation of undefined template 'is_integer<double>'
    //  typename is_integer<T>::type;
    cout << "func_concepts_add(1.0, 20) = " << func_concepts_add(1.0, 20) << endl;

    return 0;
}
